const clickOutside= {
    bind(el, binding) {
        el._clickOutside = (event) => {
            // 检查点击事件是否在弹出框内部
            const path = event.composedPath && event.composedPath()
            if (path ? path.includes(el) : el.contains(event.target)) {
                return
            }
            // 如果点击在输入框上，也不关闭
            const timeSelector = el.closest('.time-selector')
            const input = timeSelector?.querySelector('.el-input')
            if (input?.contains(event.target)) {
                return
            }
            binding.value(event)
        }

        // 使用 setTimeout 确保在其他点击事件之后执行
        setTimeout(() => {
            document.addEventListener('click', el._clickOutside)
        }, 0)
    },
    unbind(el) {
        document.removeEventListener('click', el._clickOutside)
    }
}
export const Plugin = {
    install(Vue) {
        Vue.directive('clickOutside', clickOutside)
    }
}

export default Plugin;
